import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ItemData } from "../../../resource/info/ItemData";
import { EPlayerItemPosType } from "../../../../../Message/Public/EPlayerItemPosType";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { KeyBoardManager } from "../../../../../com/gengine/keyBoard/KeyBoardManager";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
//class MountListRenderer
    
    export  class MountListRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.initView();
            this.addEventListeners();
            var loc1;
            this.useHandCursor = loc1 = true;
            this.buttonMode = loc1;
            return;
        }

        /* internal  */initView(): void
        {
            this._itemBg = ObjCreate.createBg(0, 0, 38, 38, this, ImagesConst.PackItemBg);
            this._txEnable = ObjCreate.createTextField("", 5, 5, 35, 35, this);
            this._mountItem = new BaseItem();
            this._mountItem.isDropAble = false;
            this._mountItem.width = 32;
            this._mountItem.height = 32;
            this._mountItem.move(3, 3);
            this._mountItem.isShowLock = true;
            this.addChild(this._mountItem);
            this._txName = ObjCreate.createTextField("", 42, 12, 220, 20, this);
            this._txName.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._txName.multiline = true;
            this._txName.mouseEnabled = false;
            this._txName.selectable = false;
            this._overSkin = ResouceConst.getScaleBitmap(ImagesConst.Friend_over);
            this._overSkin.width = 110;
            this._overSkin.height = 43;
            this._overSkin.y = -3;
            this._selectedBg = GlobalClass.getBitmap(ImagesConst.SelectedBg);
            this._selectedBg.width = 110;
            this._selectedBg.height = 43;
            this._selectedBg.y = -3;
            this._selectedItem = GlobalClass.getBitmap(ImagesConst.SelectedItem);
            this._selectedItem.width = 38;
            this._selectedItem.height = 38;
            return;
        }

        /* internal  */addEventListeners(): void
        {
            this.addEventListener(flash.events.MouseEvent.ROLL_OVER, this.onMouseOver);
            this.addEventListener(flash.events.MouseEvent.ROLL_OUT, this.onMouseOut);
            return;
        }

        protected onMouseOver(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._itemData && !this.selected) 
            {
                addChildAt(this._overSkin, 0);
            }
            return;
        }

        protected onMouseOut(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (!_selected) 
            {
                if (this._overSkin.parent) 
                {
                    removeChild(this._overSkin);
                }
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            super.data = arg1;
            this._itemData = arg1 as ItemData;
            if (this._itemData) 
            {
                if (this._itemData.posType != EPlayerItemPosType._EPlayerItemPosTypeRole) 
                {
                    this._txName.htmlText = ItemsUtil.getItemName(this._itemData);
                    this._txName.y = 10;
                }
                else 
                {
                    this._txName.htmlText = "<textFormat leading=\'5\'>" + ItemsUtil.getItemName(this._itemData) + "<br>" + HTMLUtil.addColor(Language.getString(70042), GlobalStyle.color6) + "</textFormat>";
                    this._txName.y = 0;
                }
                var loc2;
                this.useHandCursor = loc2 = true;
                this.buttonMode = loc2;
                this._mountItem.itemData = this._itemData;
                this._mountItem.dragSource = this._itemData;
                loc1 = "";
                loc1 = Language.getString(54292);
                loc1 = HTMLUtil.addColor(loc1, GlobalStyle.color2);
                this.toolTipData = "<textFormat leading=\'5\'>" + loc1 + "</textFormat>";
            }
            else 
            {
                this._txName.text = "";
                this._mountItem.dragSource = null;
                this._mountItem.itemData = null;
            }
            if (this._mountItem.itemData != null) 
            {
                this.mouseEnabled = true;
                this.mouseChildren = true;
            }
            else 
            {
                this.mouseEnabled = false;
                this.mouseChildren = false;
            }
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            if (KeyBoardManager.ctrlKey) 
            {
                return;
            }
            super.selected = arg1;
            if (arg1) 
            {
                if (this._itemData) 
                {
                    addChildAt(this._selectedBg, 0);
                    addChildAt(this._selectedItem, 1);
                }
            }
            else 
            {
                if (this._selectedBg.parent) 
                {
                    removeChild(this._selectedBg);
                }
                if (this._selectedItem.parent) 
                {
                    removeChild(this._selectedItem);
                }
                if (this._itemBg.parent == null) 
                {
                    addChildAt(this._itemBg, 1);
                }
            }
            if (this._overSkin.parent) 
            {
                removeChild(this._overSkin);
            }
            return;
        }

        /* internal */ /* var */_itemBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_txEnable: Object /* flash.text.TextField */;

        /* internal */ /* var */_txName: Object /* flash.text.TextField */;

        /* internal */ /* var */_overSkin: ScaleBitmap;

        /* internal */ /* var */_selectedBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_selectedItem: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_mountItem: BaseItem;

        protected /* var */_itemData: ItemData;
    }
